<!DOCTYPE html	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	template="/template/template_layout_lrt.xhtml"
	xmlns:s="http://sduept.security.el/func">
	<ui:define name="head">
		<style>
.ui-button, .ui-button span, button.ui-button.ui-state-default span,
	.ui-button.ui-state-default span {
	font-weight: normal
}

.ui-panelgrid {
	width: 95%;
	margin: 10px;
}

.ui-rowgroup-header {
	text-align: left !important;
} 
</style>
	</ui:define>
	<ui:define name="top-box-tools">
		<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
			<p:commandButton value="是" type="button"
				styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
			<p:commandButton value="否" type="button"
				styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
		</p:confirmDialog>
		<h:form id="btnForm">
			<p:growl id="msgs" showDetail="true" />
			<p:toolbar id="btnBar">
				<f:facet name="left">
					<p:commandButton icon="fa fa-plus" value="新建模板" style="margin-left:5px" id="create"
						actionListener="#{assessmentTemplateController.preCreateTemplate()}"
						oncomplete="PF('editDialog').show()" update=":editForm"
						rendered="#{s:hasPermission(session,'dwfxpg_sbyhgl_pjmbgl_xjmb')}" />
						
					<p:commandButton icon="fa fa-pencil" value="编辑模板" style="margin-left:5px" id="edit"
						actionListener="#{assessmentTemplateController.preEditTemplate()}"
						oncomplete="PF('editDialog').show()" update=":editForm"
						disabled="#{!assessmentTemplateController.showTemplateEdit}"
						rendered="#{s:hasPermission(session,'dwfxpg_sbyhgl_pjmbgl_bjmb')}" />
					
					<p:commandButton value="编辑模板项" style="margin-left:5px" icon="fa fa-pencil" id="editItem"
						rendered="#{s:hasPermission(session,'dwfxpg_sbyhgl_pjmbgl_bjmbx')}"
						actionListener="#{assessmentTemplateController.preEditTemplateItem()}"
						disabled="#{!assessmentTemplateController.showTemplateItemEdit}"
						oncomplete="PF('editTemplateItemDialog').show()" update=":editTemplateItemForm"/>
						
					<p:commandButton icon="fa fa-trash-o" value="删除" style="margin-left:5px"
						rendered="#{s:hasPermission(session,'dwfxpg_sbyhgl_pjmbgl_sc')}"
						actionListener="#{assessmentTemplateController.delete()}"
						update=":leftForm:tree msgs btnForm:btnBar :rightForm:plist :detailForm:plist">
						<p:confirm header="提示" message="该记录下的所有记录都将被删除，确定删除吗?" icon="ui-icon-alert" />
					</p:commandButton>
					
				</f:facet>
			</p:toolbar>
		</h:form>
		<h:form id="editForm">
			<p:dialog id="editDialog" widgetVar="editDialog" width="650" height="300"
				header="#{assessmentTemplateController.selectedTemplate == null? '新建模板':'编辑模板' }">
				<p:toolbar>
					<f:facet name="left">
						<p:commandButton value="保存" icon="ui-icon-disk" 
							actionListener="#{assessmentTemplateController.saveTemplate}" 
							oncomplete="PF('editDialog').hide()" update=":leftForm:tree :btnForm:msgs :rightForm:plist"/>
					</f:facet>
				</p:toolbar>
				<p:outputPanel style="text-align:center;">
					<p:panelGrid style="text-align:center">
						<p:row>
							<p:column>
								<h:outputText value="模板名称：" />
							</p:column>
							<p:column colspan="3">
								<h:inputTextarea required="true" requiredMessage="模板名称不允许为空" value="#{assessmentTemplateController.currentTemplate.name}" style="width:98%"/>
							</p:column>
						</p:row>
						<p:row>
							<p:column>
								<h:outputText value="序号:" />
							</p:column>
							<p:column>
								<p:inputNumber value="#{assessmentTemplateController.currentTemplate.num}" minValue="1" decimalPlaces="0"/>
							</p:column>
							<p:column>
								<h:outputText value="创建时间:" />
							</p:column>
							<p:column>
								<p:calendar navigator="true" pattern="yyyy-MM-dd HH:mm:ss"
									value="#{assessmentTemplateController.currentTemplate.updateTime}" />
							</p:column>
						</p:row>
						<p:row>
							<p:column>
								<h:outputText value="评价标准："/>
							</p:column>
							<p:column colspan="3">
								<p:selectOneMenu value="#{assessmentTemplateController.currentTemplate.standardVersion}" style="width:98%;margin-top:5px;margin-bottom:5px;">
									<f:selectItems value="#{assessmentTemplateController.avaliableStands}" var="item" itemValue="#{item.id}" itemLabel="#{item.content}" />
								</p:selectOneMenu>
							</p:column>
						</p:row>
						<p:row>
							<p:column>
								<h:outputText value="模板类型："/>
							</p:column>
							<p:column>
								<p:selectOneMenu value="#{assessmentTemplateController.templateType}" style="width:90%">
									<f:selectItem itemLabel="公用模板" itemValue="0"/>
									<f:selectItem itemLabel="私有模板" itemValue="1"/>
								</p:selectOneMenu>
							</p:column>
							<p:column>
								<h:outputText value="选择检查站："/>
							</p:column>
							<p:column>
								<p:commandButton icon="fa fa-plus" value="变电站" style="margin-left:5px" update=":btnForm:msgs :btnForm:btnBar"
									actionListener="#{assessmentTemplateController.openStationMultipleSelectorDialog}" >
									<p:ajax event="dialogReturn" listener="#{assessmentTemplateController.onStationsChosen}" />
								</p:commandButton>
							</p:column>
						</p:row>
					</p:panelGrid>
				</p:outputPanel>
			</p:dialog>
		</h:form>
		<h:form id="editTemplateItemForm">
			<p:dialog id="editTemplateItemDialog" widgetVar="editTemplateItemDialog" header="编辑模板项" width="710px" height="350px">
				<p:toolbar>
					<f:facet name="left">
						<p:commandButton value="保存" oncomplete="PF('editTemplateItemDialog').hide()"  
							actionListener="#{assessmentTemplateController.saveTemplateItemEdit}" 
							update=":leftForm:tree :rightForm:plist :btnForm:msgs" />
					</f:facet>
				</p:toolbar>
				<p:panelGrid style="text-align:center">
					<p:row>
						<p:column>
							<h:outputText value="模板名称" />
						</p:column>
						<p:column>
							<h:inputTextarea readonly="true" rows="2" style="width:100%" value="#{assessmentTemplateController.selectedTemplateItem.assessmentTemplate.name}" />
						</p:column>
					</p:row>
					<p:row>
						<p:column>
							<h:outputText value="变电站" />
						</p:column>
						<p:column>
							<h:inputText readonly="true" style="width:100%" value="#{assessmentTemplateController.getStationName()}" />
						</p:column>
					</p:row>
					<p:row>
						<p:column>
							<h:outputText value="模板项名称" />
						</p:column>
						<p:column>
							<p:inputText style="width:100%" value="#{assessmentTemplateController.selectedTemplateItem.name}" />
						</p:column>
					</p:row>
					<p:row>
						<p:column>
							<h:outputText value="创建时间" />
						</p:column>
						<p:column>
							<p:calendar value="#{assessmentTemplateController.selectedTemplateItem.updateTime}" 
								navigator="true" pattern="yyyy-MM-dd HH:mm:ss" />
						</p:column>
					</p:row>
					<!-- <p:row>
						<p:column>
							<h:outputText value="评价项目" />
						</p:column>
						<p:column>
							<p:commandButton value="编辑" style="margin-left:5px" update=":btnForm:msgs :btnForm:btnBar"
								actionListener="#{assessmentTemplateController.openStandardSelectorDialog()}" >
								<p:ajax event="dialogReturn" update=":btnForm:msgs" listener="#{assessmentTemplateController.onStandardsChosenWhenEdit}" />
							</p:commandButton>
						</p:column>
					</p:row> -->
				</p:panelGrid>
			</p:dialog>
		</h:form>
	</ui:define>
	<ui:define name="left-box-title" style="border:0">
		模板列表
	</ui:define>
	<ui:define name="left-box-body">
		<h:form id="leftForm">
			<p:panel style="border:0;width:98%">
				<p:tree value="#{assessmentTemplateController.templateRoot}" var="node"
					dynamic="true" id="tree" widgetVar="tree" animate="true"
					selectionMode="single" style="border:0">
					<p:ajax event="expand" update="tree" listener="#{assessmentTemplateController.onNodeExpand}" />
					<p:ajax event="select" listener="#{assessmentTemplateController.onNodeSelect}"
						update=":btnForm:edit :btnForm:editItem :rightForm:plist editForm :detailForm:plist" />
					<p:treeNode type="templateType" icon="fa fa-home">
						<h:outputText value="#{node}"/>
					</p:treeNode>
					<p:treeNode type="template" >
						<h:outputText value="#{node.name}"/>
					</p:treeNode>
					<p:treeNode type="templateItem" >
						<h:outputText value="#{node}" />
					</p:treeNode>
				</p:tree>
			</p:panel>
		</h:form>
	</ui:define>
	<ui:define name="right-box-title">
		模板详情
	</ui:define>
	<ui:define name="right-box-body">
		<h:form id="rightForm">
			<p:dataTable id="plist" value="#{assessmentTemplateController.dtos}"
				var="dto" emptyMessage="无记录" style="text-align:center" >
				<p:column headerText="所属模板" groupRow="true" width="15%">
					<h:outputText value="#{dto.template.name}" />
				</p:column>
				<p:column headerText="模板类型" groupRow="true" width="10%">
					<h:outputText value="#{dto.type.label}" />
				</p:column>
				<p:column headerText="模板项" groupRow="true" width="15%">
					<h:outputText value="#{dto.templateItem.name}" />
				</p:column>
				<p:column headerText="评价项目" width="60%" >
					<p:rowExpansion>
						<p:repeat value="#{dto.stands}" var="stand" >
							<div class="row" style="float:left;padding-left: 10px;text-align:left; width: 100%" id="docDiv">
								<h:outputText value="#{stand.content}" />
							</div>
						</p:repeat>
					</p:rowExpansion>
				</p:column>
				<p:column width="5%" >
					<p:commandLink value="详细" style="text-decoration:underline;color:red;" 
						oncomplete="PF('detailDlg').show()" update="detailForm"
						actionListener="#{assessmentTemplateController.showTemplateItemDetail(dto.templateItem)}"/>
				</p:column>
			</p:dataTable>
		</h:form>
		<h:form id="detailForm">
			<p:dialog id="detailDlg" widgetVar="detailDlg" header="详细信息" width="1400px" height="700px">
				<s:dataTable id="plist" value="#{assessmentTemplateController.templateDetails}"
					var="item" sortBy="#{item.projectOrder}"
					emptyMessage="无记录" style="text-align:left" >
					<f:facet name="header" >
						<h:outputText style="text-align:center" value="#{assessmentTemplateController.tableTitle}" />
					</f:facet>
					<p:headerRow>
						<p:column colspan="3">
							<h:outputText value="#{item.projectNo}、#{item.projectName}" />
						</p:column>
					</p:headerRow>
					<s:column headerText="评价项目" groupRow="true" style="width:10%">
						<h:outputText value="#{item.itemNo}.#{item.itemName}" />
					</s:column>
					<s:column headerText="检查要素及要求" groupRow="true" style="width:45%">
						<h:outputText value="#{item.inspectionNo}.#{item.inspectionName}" />
					</s:column>
					<s:column headerText="评分标准" style="width:45%;">
						<h:outputText value="#{item.scoreNo}.#{item.scoreName}" />
					</s:column>
				</s:dataTable>
			</p:dialog>
		</h:form>
	</ui:define>
</ui:composition>
